package com.itheima;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*
    获取路径的相关方法
 */

@WebServlet("/servletDemo01")
public class ServletDemo01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//1 获取虚拟目录名称  getContextPath()
        String contextPath = req.getContextPath();
        System.out.println(contextPath);
        System.out.println("-----");
//        2.获取Servlet映射路径 getServletPath()
        String servletPath = req.getServletPath();
        System.out.println(servletPath);
        System.out.println("-----");
//        3. 获取访问者ip getRemoteAddr()
        String ip = req.getRemoteAddr();
        System.out.println(ip);
        System.out.println("-----");
        //获取请求消息的数据 getQueryString()
        String queryString = req.getQueryString();
        System.out.println(queryString);
        System.out.println("-----");
//        获取统一资源标识符 getRequestURI()
        String requestURI = req.getRequestURI();
        System.out.println(requestURI);
        System.out.println("-----");
        //获取统一资源定位符 getRequestUrl


        StringBuffer requestURL = req.getRequestURL();
        System.out.println(requestURL);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
